package de.fhkiel.webservice.dao;

import java.util.Set;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import de.fhkiel.webservice.data.Payment;
import de.fhkiel.webservice.data.PaymentRow;

@Repository
public class PaymentDAOImpl implements PaymentDAO {

	@Autowired
    private SessionFactory sessionFactory;
	
	@Override
	public void addPayment(Payment payment) {
		Set<PaymentRow> paymentRows = payment.getPaymentrow();
		payment.setPaymentrow( null );
		sessionFactory.getCurrentSession().save(payment);
		for ( PaymentRow row : paymentRows ) {
			row.setPayment( payment );
			sessionFactory.getCurrentSession().save(row);
		}
	}

}
